package com.pswv2.socket;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;  
import java.io.InputStream;  
import java.io.InputStreamReader;  
import java.io.PrintWriter;  
import java.net.Socket;  
  
import javax.servlet.ServletContext;

import javassist.util.proxy.MethodHandler;  

public class SocketOperate extends Thread{
	 private Socket socket;  
     
     public SocketOperate(Socket socket) {  
        this.socket=socket;  
     }  
    @Override
    public void run()  {  
        String s;   //接受客户端字符串
         try{     
        	 DataInputStream in=new DataInputStream(socket.getInputStream());
        	 DataOutputStream pw =new DataOutputStream(socket.getOutputStream());
        	 while((s=in.readUTF())!=null){
                 System.out.println("Client  "+s);   //读取输入流
                 if ("end".equals(s)) {
                	 pw.writeUTF(s);
                	 System.out.println("准备关闭socket");
                	 break;
                 }
 				}
        	 pw.close();
        	 in.close();
        	// socket.close();
            }catch(IOException ex){     
  
            }finally{     
                
            }     
     }  
}
